<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>修改个人资料</title>
    <style media="screen">
      *{
        padding: 0;
        margin: 0;
      }
      ul{
        margin-left: 200px;
        list-style: none;
        display: none;
      }
      ul li{
        margin-top: 20px;
      }
      #num0,#num1,#num2,#num3,#num4,#num5{
        width: 200px;
      }
      #num6,#num7{
        width: 200px;
        height: 80px;
      }
      #span3{
        display: none;
      }
    </style>
  </head>
  <body>
    <span id="span1"></span>
    <span id="span2">个人中心</span>

    <ul id="ul_one">
        <li id="li0"><span>账&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp号:</span> <input type="text" name="num0" id="num0" value=""></li>
        <li id="li1"><span>密&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp码:</span> <input type="text" name="num1" id="num1" value=""></li>
        <li id="li2"><span>电&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp话:</span> <input type="text" name="num2" id="num2" value=""></li>
        <li id="li3"><span>姓&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp名:</span> <input type="text" name="num3" id="num3" value=""></li>
        <li id="li4"><span>年&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp龄:</span> <input type="text" name="num4" id="num4" value=""></li>
        <li id="li5"><span>性&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp别:</span> <input type="text" name="num5" id="num5" value=""></li>
        <li id="li6"><span>住&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp址:</span> <input type="text" name="num6" id="num6" value=""></li>
        <li id="li7"><span>个人签名:</span><input type="text" name="num7" id="num7" value=""></li>
        <span id="span3"></span>
        <li><input type="submit" name="submit" id="submit" value="提交"></li>
    </ul>
  </body>
  <script type="text/javascript">
  //页面加载完成调用函数
    window.onload =function(){
      if (window.XMLHttpRequest) {
          var request = new XMLHttpRequest();
      } else {
          var request = new ActiveXObject("Microsoft.XMLHTTP");
      }

      var url ="6.php";
      request.open("GET",url,true);
      request.send(null);
      request.onreadystatechange = function() {
        //  得到当前登陆的账号名
          if (request.readyState == 4 && request.status == 200) {


              var title =document.getElementById('span1');
              span1.innerHTML ="欢迎您:"+request.responseText;
              //获取账号
              var num0 =document.getElementById('num0');
              num0.value =request.responseText;
              start();
          };

      }
    }

//等到当前对应注册时候随机设置的id，以便后边进行数据的更改
    function start(){
      if (window.XMLHttpRequest) {
          var request = new XMLHttpRequest();
      } else {
          var request = new ActiveXObject("Microsoft.XMLHTTP");
      }

      var url ="9.php";
      request.open("GET",url,true);
      request.send(null);
      request.onreadystatechange = function() {

          if (request.readyState == 4 && request.status == 200) {


              var span3 =document.getElementById('span3');
              span3.innerHTML =request.responseText;


          };
          // 如果调用函数的时候，传入了成功的回调函数，我们调用这个函数
      }
    }

//给个人中心设置点击事件，进行修改内容
var set =document.getElementById('span2');
    set.onclick=function(){

      if (window.XMLHttpRequest) {
          var request1 = new XMLHttpRequest();
      } else {
          var request1 = new ActiveXObject("Microsoft.XMLHTTP");
      }

      var url ="7.php";
      request1.open("GET",url,true);
      request1.send(null);
      request1.onreadystatechange = function() {
          //获取密码
          if (request1.readyState == 4 && request1.status == 200) {

              var num1 =document.getElementById('num1');
              num1.value =request1.responseText;
              var ul_one =document.getElementById('ul_one');
              ul_one.style.display ="block";
              update();
          };

      }

    }

//进行数据修改请求数据
var myDate = new Date();
var mytime=myDate.toLocaleString();
    var submit =document.getElementById('submit');
    submit.onclick =function(){
      if (window.XMLHttpRequest) {
          var request2 = new XMLHttpRequest();
      } else {
          var request2 = new ActiveXObject("Microsoft.XMLHTTP");
      }
//设置发送的数据
    var url ="8.php?username="+document.getElementById('num0').value+"&password="+document.getElementById('num1').value+"&telephone="+document.getElementById('num2').value+"&name="+document.getElementById('num3').value+"&age="+document.getElementById('num4').value
    +"&sex="+document.getElementById('num5').value+"&address="+document.getElementById('num6').value+"&signature="+document.getElementById('num7').value
    +"&identity="+document.getElementById('span3').innerHTML+"&time="+mytime;
      request2.open("GET",url,true);
      request2.send(null);
      request2.onreadystatechange = function() {

          if (request2.readyState == 4 && request2.status == 200) {

             alert("提交成功");
           window.location.reload();

          };
          // 如果调用函数的时候，传入了成功的回调函数，我们调用这个函数
      }
    }




function update(){

  if (window.XMLHttpRequest) {
      var request7 = new XMLHttpRequest();
  } else {
      var request7 = new ActiveXObject("Microsoft.XMLHTTP");
  }

  var url ="12.php";
  request7.open("GET",url,true);
  request7.send(null);
  request7.onreadystatechange = function() {
      //获取密码
      if (request7.readyState == 4 && request7.status == 200) {

        json =request7.responseText;
        
          startx();
      };

  }


}
function startx(){
  var object =JSON.parse(json);
  document.getElementById('span1').innerHTML =object[0].username;
  document.getElementById('num0').value =object[0].username;
  document.getElementById('num1').value =object[0].password;
  document.getElementById('num2').value =object[0].telephone;
  document.getElementById('num3').value =object[0].name;
  document.getElementById('num4').value =object[0].age;
  document.getElementById('num5').value =object[0].sex;
  document.getElementById('num6').value =object[0].address;
  document.getElementById('num7').value =object[0].signature;

}

  </script>
</html>
